package com.yance.fim.controller;

import cn.hutool.extra.mail.MailUtil;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import com.yance.fim.User;
import com.yance.fim.entity.ImUser;
import com.yance.fim.service.IImUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author yance
 */
@RestController
@RequestMapping("/api")
public class HazelcastController {
    @Autowired
    private HazelcastInstance hazelcastInstance;
    @Autowired
    private IImUserService iImUserService;

    @GetMapping("/getHazelcastInstance")
    public void getHazelcastInstance() {
        IMap<String, User> mUserMap = hazelcastInstance.getMap("users");
        hazelcastInstance.getMap("users");
        User user = new User();
        user.setAge(18);
        user.setName("杨帅哥");
        user.setQq("2444864349");
        mUserMap.put("1", user);
        User user1 = mUserMap.get("1");
        System.out.println(user1);
        mUserMap.delete("1");
        User user2 = mUserMap.get("1");
        System.out.println(user2);
    }

    @ApiOperation(value = "测试新增用户接口")
    @GetMapping("/addUser")
    public void addUser() {
        ImUser user = new ImUser();
        user.setAge(19);
        user.setAvatar("http://www.baidu.com");
        user.setNickName("yance");
        user.setUserAccount("121212");
        user.setCreateTime(new Date());
        iImUserService.save(user);
    }

    @ApiOperation(value = "测试邮件发送接口")
    @GetMapping("/sendEmail")
    public void sendEmail() {
        MailUtil.send("yancestyle@foxmail.com", "测试", "邮件来自FIM测试", false);
    }
}
